package com.china08.yxyapi.api.manage.sch.platform.xiaoben.auth;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsSchoolLesson;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.repository.db.YxyLessonsSchoolLessonRepository;

@CrossOrigin
@RestController
public class KeChengAuthUpdVipController extends YxyApiBaseController {

    @Autowired
    YxyLessonsSchoolLessonRepository schoolLessonRepository;

    @RequestMapping(value = "/api_yw/manage/sch/xiaoben/auth/kecheng/upd/vip", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void process(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String lessonId = reqModel.lessonId;
        Integer vip = reqModel.vip;

        YxyLessonsSchoolLesson yxyLessonsSchoolLesson = schoolLessonRepository.findById(lessonId);
        if (null != yxyLessonsSchoolLesson) {
            yxyLessonsSchoolLesson.setVip(vip);
            schoolLessonRepository.save(yxyLessonsSchoolLesson);
        }
    }

    public static class ReqModel extends YxyApiPageReqModel {
        public String lessonId;
        public Integer vip;
    }
}
